<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var searchRange = function (nums, target) {
      return nums.map(n => n - target).reduce((p, n, i) => {
        if (n === 0) {
          if (p[0] === -1) {
            p[0] = i
          }
          p[1] = i
        }
        return p
      }, [-1, -1])
    };
    console.log(searchRange([5, 7, 7, 8, 8, 8, 8, 8, 10], 8))
  </script>
</body>

</html>